package com.ifast.common.utils.qukan;

import java.io.IOException;

import okhttp3.HttpUrl;
import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;

/**
 * 添加功能请求头
 * @author ShiQiang
 *
 */
public class CommonInterceptor implements Interceptor{

	@Override
	public Response intercept(Interceptor.Chain chain) throws IOException { 
		Request oldRequest = chain.request(); 
        // 添加新的参数
		HttpUrl.Builder authorizedUrlBuilder = oldRequest.url().newBuilder().scheme(oldRequest.url().scheme())
				.host(oldRequest.url().host()); 
		// 新的请求
		Request newRequest = oldRequest.newBuilder().method(oldRequest.method(), oldRequest.body())
				.url(authorizedUrlBuilder.build())
				.addHeader("Content-Type", "application/json;charset=UTF-8")
				.addHeader("Accept", "application/json") 
				.build();  
		return chain.proceed(newRequest);
	}
}